#include "menu.h"

uint8 MenuSelect;
uint8 MenuTimeout;			//timeout return to default menu

uint8 MenuBuff[MENU_BUFF_LENTH];

pFunc	pDefaultMenu;
pFunc	pCurrentMenu;

void MenuInitialize(void)
{
	pDefaultMenu = MenuPrcHome;
	pCurrentMenu = MenuPrcHome;
	
}

//Display:Home
//Display cover bmp
//if joysig_down, go to MenuProc12
//if joysig_left, return to Default Menu
void MenuPrcHome(void){
	OLEDClear();
	OLEDDrawBMP(LogoBMP);
	pDefaultMenu = MenuPrcHome;
	
	while(1)
	{
		if(JoySigDown)
		{
			JoySigDown = 0;
			pCurrentMenu = MenuPrcASR;
			break;
		}
		if(JoySigRight)
		{
			JoySigRight = 0;
			pCurrentMenu = MenuPrcSetup;
			break;
		}
	}
}

//Display:ASR
//Dispaly ASR command(scrolling)
//if joysig_up, go to MenuProc11
//if joysig_down, go to MenuProc13
//if joysig_left, return to Default Menu
void MenuPrcASR(void){
	OLEDClear();
	OLEDPrintString(0,0,"Current ASR Command:");
	pDefaultMenu = MenuPrcASR;
	
	while(1)
	{
		OLEDPrintString(0,1,ASRDebugBuff);
		if(JoySigUp)
		{
			JoySigUp = 0;
			pCurrentMenu = MenuPrcHome;
			break;
		}
		if(JoySigDown)
		{
			JoySigDown = 0;
			pCurrentMenu = MenuPrcJoys;
			break;
		}
		if(JoySigRight)
		{
			JoySigRight = 0;
			pCurrentMenu = MenuPrcSetup;
			break;
		}
	}
}

//Display:Joystick
//Display joystick data
//if joysig_up, go to MenuProc12
//if joysig_down, go to MenuProc14
//if joysig_left, return to Default Menu
void MenuPrcJoys(void){
	OLEDClear();
	OLEDPrintString(0,0,"Joystick data:");
	pDefaultMenu = MenuPrcJoys;
	
	while(1)
	{
		sprintf(MenuBuff,"JoysX:%d,JoysY:%d",JoysX,JoysY);
		OLEDPrintString(0,1,MenuBuff);
		
		sprintf(MenuBuff,"U:%c,D:%c,L:%c,R:%c",JoySigUp?'X':'O',JoySigDown?'X':'O',JoySigLeft?'X':'O',JoySigRight?'X':'O');
		OLEDPrintString(0,2,MenuBuff);
		
		if(JoySigUp)
		{
			JoySigUp = 0;
			pCurrentMenu = MenuPrcASR;
			break;
		}
		if(JoySigDown)
		{
			JoySigDown = 0;
			pCurrentMenu = MenuPrcBLED;
			break;
		}
		if(JoySigRight)
		{
			JoySigRight = 0;
			pCurrentMenu = MenuPrcSetup;
			break;
		}
	}
}

void MenuPrcBLED(void){
	
}

void MenuPrcMotor(void){
		
}

void MenuPrcIMU(void){
			
}

void MenuPrcDebug(void){
				
}

void MenuPrcSetup(void){
	
}
